package com.whjz.dcfs.jzxx.struts.service;

import com.whjz.dcfs.jzxx.dao.IDcfsJzSbJbxxDAO;
import com.whjz.dcfs.jzxx.model.DcfsJzSbJbxx;
import com.whjz.dcfs.pub.excel.entity.ProductEditExcelVO;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;


/**
 * Created by ehsy_it on 2016/7/10.
 */

public class JZSBService {
    private Logger logger = LoggerFactory.getLogger(JZSBService.class);

    @Autowired
    public IDcfsJzSbJbxxDAO dcfsJzSbJbxxDAO;

    public int insertDcfsJzSbJbxxByExcel(List<ProductEditExcelVO> jzsbs){
        int count = 0;//统计添加成功的条数
        for(ProductEditExcelVO productEditExcelVO:jzsbs){
            DcfsJzSbJbxx dcfsJzSbJbxx = new DcfsJzSbJbxx();
            try {
                BeanUtils.copyProperties(dcfsJzSbJbxx, productEditExcelVO);
                dcfsJzSbJbxx.setBdjd(dcfsJzSbJbxx.getJzfstxjd());
                dcfsJzSbJbxx.setBdwd(dcfsJzSbJbxx.getJzfstxwd());
                dcfsJzSbJbxx.setJzflag("0");//0代表正常 1代表删除 看本类第78行
                dcfsJzSbJbxxDAO.insertDcfsJzSbJbxx(dcfsJzSbJbxx);
                count++;
            }catch (Exception e){
                logger.error(e.getMessage(), e);
                throw new RuntimeException("第"+productEditExcelVO.getExcelNo()+"行的数据格式有问题，请检查");
            }
        }
        return count;
    }
}